package sprinklerbee.utils;

import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CommonUtils {
	
	public static String transferTime(Time src){
		return new SimpleDateFormat("HH:mm").format(src);
	}
	public static String transferTime(Date src){
		return new SimpleDateFormat("HH:mm").format(src);
	}
	public static Time stringToTime(String src){
		Date d = null;
		try {
			d = new SimpleDateFormat("HH:mm:ss").parse(src);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Time time=new Time(d.getTime());
		return time.valueOf(src);
	}
	
	public static String getWeekDay(Calendar c) {
		if (c == null) {
			return "Mon";
		}
		if (Calendar.MONDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Mon";
		}
		if (Calendar.TUESDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Tue";
		}
		if (Calendar.WEDNESDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Wed";
		}
		if (Calendar.THURSDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Thur";
		}
		if (Calendar.FRIDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Fri";
		}
		if (Calendar.SATURDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Sat";
		}
		if (Calendar.SUNDAY == c.get(Calendar.DAY_OF_WEEK)) {
			return "Sun";
		}
		return "Mon";
	}
}
